import 'package:device_info/device_info.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_study/utils/DioUtil.dart';
import 'package:logger/logger.dart';
import 'package:provider/provider.dart';

class KModel with ChangeNotifier {
  int value = 0;

  changeValueAndNotifier() {
    ++value;
    notifyListeners();
  }
}

class ProviderActivity extends StatefulWidget {
  @override
  _ProviderActivityState createState() => _ProviderActivityState();
}

class _ProviderActivityState extends State<ProviderActivity> {
  @override
  void initState() {
    // TODO: implement initState
    SpUtil.putString("username", "itzj");
    super.initState();
  }
  @override
  Widget build(BuildContext k) {
    return Scaffold(
      appBar: AppBar(
        title: Text(''),
      ),
      body: ChangeNotifierProvider(
        create: (ctx) => KModel(),
        child: Center(
            child: Consumer<KModel>(
          builder: (context, KModel model, child) => RaisedButton(
            child: Text(model.value.toString()),
            onPressed: () {
              Provider.of<KModel>(context, listen: false)
                  .changeValueAndNotifier();
              DioUtil.getDeviceInfo().then((info) {
                Logger().wtf(info);
              });
              Logger().wtf("Sp==${SpUtil.getString("username")}");
            },
          ),
        )),
      ),
//        body: ChangeNotifierProvider.value(
//          value: KModel(),
//          child: Center(
//              child: Consumer<KModel>(
//            builder: (context, KModel model, child) => RaisedButton(
//              child: Text(model.value.toString()),
//              onPressed: () {
//                Provider.of<KModel>(context, listen: false)
//                    .changeValueAndNotifier();
////                      model.changeValueAndNotifier();
//                DioUtil.getDeviceInfo().then((info) {
//                  Logger().wtf(info);
//                });
//              },
//            ),
//          )),
//        )
    );
  }
}
